<template>
    <div class="xl-table">
        <xlUntil text="政策原文管理" @addForm="addForm" :queryParam="queryParam" @delBatch="delBatch"
                 @searchKeyWord="searchKeyWord" :searchColumns="columns" :export-xls-data="columns"
                 :until-visible="false"
                 :export-xls-url="url.exportXlsUrl"
                 >
            <template #search>
                <a-select v-model="queryParam.policyType" placeholder="请选择政策类型" allowClear style="margin-right: 16px;width: 150px;">
                    <a-select-option :value="item.codeMasterValue" :key="index"
                                     v-for="(item,index) in $store.getters.dictionary['POLICY_TYPE']">
                        {{item.codeMasterName}}
                    </a-select-option>
                </a-select>
                <a-select v-model="queryParam.policyAreaCode" placeholder="请选择区域" allowClear style="margin-right: 16px;width: 150px;">
                    <a-select-option :value="item.codeMasterValue" :key="index"
                                     v-for="(item,index) in $store.getters.dictionary['PUBLISH_AREA']">
                        {{item.codeMasterName}}
                    </a-select-option>
                </a-select>
                <a-select v-model="queryParam.urlInvalid" placeholder="原文地址是否失效" allowClear style="margin-right: 16px;width: 150px;">
                    <a-select-option :value="false">有效</a-select-option>
                    <a-select-option :value="true">失效</a-select-option>
                </a-select>
            </template>
        </xlUntil>
        <div class="xl-table-content">
            <xlTable
                :columns="columns"
                :dataSource="data"
                rowKey="id"
                :pagination="pagination"
                :loading="loading"
                @change="handleTableChange"
                bordered
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                >
                <template v-slot:action="scope">
                    <a @click="editForm(scope.record)">编辑</a>
                    <a-divider type="vertical"/>
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多
                            <a-icon type="down"/>
                        </a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <a :href="scope.record.policySourceUrl" target="_blank">预览</a>
                            </a-menu-item>
                            <a-menu-item @click="seeForm(scope.record)">
                                <a>查看</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => delForm(scope.record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </template>
            </xlTable>
        </div>
        <xlForm ref="xlForm" @handleOk="handleOk"></xlForm>
        <seeForm ref="seeForm"></seeForm>
    </div>
</template>

<script>

import xlForm from './model/form'
import seeForm from './model/seeForm'
import xlMixin from '../../../components/mixin/index'
import {policyOriginalTextDetailGet} from "@/assets/api/policy";

export default {
    name: "index",
    mixins: [xlMixin],
    data() {
        return {
            data: [],
            columns: [
                {
                    title: '序号',
                    key: 'rowIndex',
                    align: "center",
                    fixed: 'left',
                    width: '180px',
                    sorter: (a) => a.id,//排序
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '编号',
                    dataIndex: 'policyOriginalTextCode',
                    type: 'input',
                    formVisible: true,
                    tableVisible: true
                },
                {
                    title: '政策名称',
                    dataIndex: 'policyTitle',
                    type: 'input'
                },
                {
                    title: '政策类型',
                    dataIndex: 'policyType',
                    type: 'select',
                    typeData: 'POLICY_TYPE'
                },
                {
                    title: '政策来源',
                    dataIndex: 'policySource',
                    type: 'input'
                },
                {
                    title: '政策原文地址',
                    dataIndex: 'policySourceUrl',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '原文地址是否失效',
                    dataIndex: 'urlInvalid',
                    type: 'radio',
                    typeData: [
                        {
                            dataName: '失效',
                            dataValue: true
                        },
                        {
                            dataName: '有效',
                            dataValue: false
                        }
                    ],
                    span: 2
                },
                {
                    title: '政策区域编码',
                    dataIndex: 'policyAreaCode',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '政策区域名称',
                    dataIndex: 'policyAreaName',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '发布部门编码',
                    dataIndex: 'publishDepartmentCode',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '发布部门名称',
                    dataIndex: 'publishDepartmentName',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '发布人',
                    dataIndex: 'createBy',
                    type: 'input',
                    formVisible: true
                },
                {
                    title: '发布时间',
                    dataIndex: 'publishDateTime',
                    type: 'date',
                    typeData: 'dateTime'
                },
                {
                    title: '政策原文内容',
                    dataIndex: 'policyOriginalTextContent',
                    type: 'editor',
                    tableVisible: true,
                    span: 2
                },
                {
                    title: '附件',
                    dataIndex: 'enclosures',
                    type: 'upload.files',
                    tableVisible: true,
                    span: 2
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: 'right',
                    width: '150px',
                    scopedSlots: {customRender: 'action'},
                }
            ],
            url: {
                list: "/system/api/policy/original/text/page/list",
                add: '/system/api/policy/original/text/_save',
                edit: '/system/api/policy/original/text/_save',
                delete: "/system/api/policy/original/text/_remove"
            }
        }
    },
    components: {
        xlForm,
        seeForm
    },
    created() {
        this.pageOnload()
        this.formatMerge()
    },
    methods: {
        addForm() {
            this.$refs.xlForm.tableTitle = '新增'
            this.$refs.xlForm.confirmLoading = false
            this.$refs.xlForm.formatForm({urlInvalid: false, policyAreaCode: 'PA3'})
            this.$refs.xlForm.type = 1
            this.$refs.xlForm.visible = true
        },
        seeForm(data) {
            policyOriginalTextDetailGet({
                param: {policyOriginalTextCode: data.policyOriginalTextCode}
            }).then(res => {
                this.$refs.seeForm.formatData(this.columns, res.result)
                this.$refs.seeForm.visible = true
            })

        },
        editForm(data) {
            policyOriginalTextDetailGet({
                param: {policyOriginalTextCode: data.policyOriginalTextCode}
            }).then(res => {
                this.$refs.xlForm.tableTitle = '修改'
                this.$refs.xlForm.confirmLoading = false
                this.$refs.xlForm.formatForm(res.result)
                this.$refs.xlForm.type = 2
                this.$refs.xlForm.visible = true
            })
        }
    }
}
</script>

<style scoped lang="less">
.xl-table {
    .xl-table-content {
        padding: 16px;
    }
}
</style>